package com.silverhaze.diamond.server.service.upgrade;

import org.jboss.xnio.log.Logger;

import javax.persistence.EntityManager;
import javax.transaction.*;
import java.io.InputStream;

/**
 * This code is part of Kg.Axion project. Treat it as strictly confidential.
 * Created by Ivan Babanin.
 * Creation date: 01.10.11 20:26
 */
public abstract class UpgradePoint {
    private boolean mandatory;

    public UpgradePoint() {
        this(false);
    }

    public UpgradePoint(boolean mandatory) {
        this.mandatory = mandatory;
    }

    public abstract void upgrade(EntityManager entityManager, UserTransaction userTransaction) throws SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException, NotSupportedException;

    public static void log(String text) {
        Logger.getLogger(DatabaseUpgradeServiceBean.class).info(text);
    }

    public static void error(String text, Exception e) {
        Logger.getLogger(DatabaseUpgradeServiceBean.class).error(text, e);
    }

    public String getDescription() {
        return "";
    }

    public boolean isMandatory() {
        return mandatory;
    }

    public static InputStream getResource(String filePath) {
        return UpgradePoint.class.getResourceAsStream("resources/" + filePath);
    }
}
